﻿''This entire method of storing and "searching" the song archive
''needs to be updated so it can handle errors and bigger data files
''The current "array" crap I'm using will not handle large amounts
''of data very effeciently. Maybe convert this over to XML?
Public Class SongLog

    Private Sub SongLog_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

    End Sub

    Private Sub SongLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intSongs, intArtists, intStations As Integer
        If Not File.Exists("songinfo.csv") Then
            MessageBox.Show("There are no songs in the log, yet.", "- SiNet Error -", MessageBoxButtons.OK, MessageBoxIcon.Hand)
            Exit Sub
        End If
        Try
            Dim songInfo As Array = Split(File.ReadAllText("songinfo.csv"), vbNewLine)
            For Each songArtist In songInfo
                intSongs += 1
                Dim infoSplit As Array = Split(songArtist.ToString, ",")
                If infoSplit.Length = 4 Then
                    If Not ComboBoxArtists.Items.Contains(infoSplit(2)) Then
                        ComboBoxArtists.Items.Add(infoSplit(2))
                        intArtists += 1
                    End If
                    If Not ComboBoxStation.Items.Contains(infoSplit(1)) Then
                        ComboBoxStation.Items.Add(infoSplit(1))
                        intStations += 1
                    End If
                End If
            Next
            LabelStats.Text = "You have listened to:" & vbNewLine & _
            intStations & " - different stations." & vbNewLine & _
            intArtists & " - different artists." & vbNewLine & _
            (intSongs - 1) & " - total songs."
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "none", MessageBoxButtons.OK)
        End Try
    End Sub

    Private Sub ButtonArtistSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonArtistSearch.Click
        Try
            TextBoxResults.Text = ""
            Dim songInfo2 As Array = Split(File.ReadAllText("songinfo.csv"), vbNewLine)
            For Each lineInfo In songInfo2
                If ComboBoxArtists.SelectedItem.ToString.Length > 0 Then
                    If lineInfo.ToString.Contains(ComboBoxArtists.SelectedItem.ToString) Then
                        TextBoxResults.AppendText(lineInfo.ToString.Replace(",", " - ") & vbNewLine)
                    End If
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonStationSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStationSearch.Click
        Try
            TextBoxResults.Text = ""
            Dim songInfo2 As Array = Split(File.ReadAllText("songinfo.csv"), vbNewLine)
            For Each lineInfo In songInfo2
                If ComboBoxStation.SelectedItem.ToString.Length > 0 Then
                    If lineInfo.ToString.Contains(ComboBoxStation.SelectedItem.ToString) Then
                        TextBoxResults.AppendText(lineInfo.ToString.Replace(",", " - ") & vbNewLine)
                    End If
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ButtonSearchText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSearchText.Click
        Try
            TextBoxResults.Text = ""
            Dim songInfo2 As Array = Split(File.ReadAllText("songinfo.csv"), vbNewLine)
            For Each lineInfo In songInfo2
                If TextBoxTextSearch.Text.ToString.Length > 0 Then
                    If lineInfo.ToString.Contains(TextBoxTextSearch.Text.ToString) Then
                        TextBoxResults.AppendText(lineInfo.ToString.Replace(",", " - ") & vbNewLine)
                    End If
                End If
            Next
            If TextBoxResults.TextLength = 0 Then
                TextBoxResults.Text = "-----------" & vbNewLine & "NOTHING WAS FOUND" & vbNewLine & "-----------"
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class